import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex)
export default new Vuex.Store({
  state:{
    token:localStorage.getItem("token"),
    staffInfo:JSON.parse(localStorage.getItem("staffInfo"))

  },
  mutations:{
    SET_TOKEN:(state,token)=>{
      state.token = token;
      localStorage.setItem("token",token);
    },
    SET_STAFFINFO:(state,staffInfo)=>{
      state.staffInfo = staffInfo;
      localStorage.setItem("staffInfo",JSON.stringify(staffInfo));
    },
    REMOVE_INFO:(state)=>{
      state.token='';
      state.staffInfo={};
      localStorage.setItem("token","");
      localStorage.setItem("staffInfo",JSON.stringify(''))
    }
  },
  getters:{
    getStaff:state => {
      return state.staffInfo;
    },
    getToken:state => {
      if (state.token == null){
        return '';
      }else {
        return state.token;
      }
    }
  },
  actions:{},
  modules:{}
})
